// 财务项相关
import { FinancialType } from '../types/financial'
import request from '../utils/request'

interface SearchType {
    [key: string]: string | {}
}
// 新增财务
export const FinPost = (carobj: FinancialType) => {
    return request.post('classes/financial', carobj)
}

// 获取财务项
export const FinGet = (page: number = 1, limit: number = 5, search = {} as SearchType) => {
    for (let i in search) {
        if (search[i] == '') {
            delete search[i];
        }
    }
    if (search.name) {
        search.name = { "$regex": `${search.name}`, "$options": "i" }

        console.log(search.name);
    }
    let skip = (page - 1) * limit
    return request.get('classes/financial', {
        params: {
            limit,
            count: 1,
            skip,
            where: search
        }
    })
}


// 编辑
export const FinUpdate = (id:string,carobj: FinancialType) => {
    return request.put('classes/financial/'+id, carobj)
}

// 编辑
export const FinDel = (id:string) => {
    return request.delete('classes/financial/'+id)
}
